/*
 * @Author: WangZhongDe
 * @Date: 2021-08-26 22:00:34
 * @LastEditors: WangZhongDe
 * @LastEditTime: 2021-08-27 15:36:40
 * @FilePath: \rust\learn3\src\main.rs
 */
  // 结构 struct
use rand::prelude::*;
use std::fmt::Debug;
use std::collections::HashMap;
#[derive(Debug)]
  struct User{
    id:i32,
    username:String,
    age:i32,
    email:String,
}
#[derive(Debug)]
enum Spreadsheetcell{
    Pid(i32),
    Name(String),
    Age(f64),
}
fn main() {
    let mut u1 = User{
        id:1,
        username:String::from("wangzhongde"),
        age:18,
        email:String::from("wangzhongde@explian.com"),
    };
    u1.age = 20;
    u1.username = String::from("wzd");
    println!("{:#?}",u1);
    let  row = vec![
        Spreadsheetcell::Pid(1),
        Spreadsheetcell::Name(String::from("wzd")),
        Spreadsheetcell::Age(18.5),
    ];
for item in row.iter(){
  match &item{
    Spreadsheetcell::Pid(pid)=>println!("{}",pid),
    Spreadsheetcell::Name(name)=>println!("{}",name),
    Spreadsheetcell::Age(age)=>println!("{}",age),
    // _ => println!("none"),
  };
 } 
 let x:u32 = random();
 println!("{}",x);

 let mut scores = HashMap::new();
 scores.insert(String::from("blue"), 10);
 let s = scores.get("blue");
 match s{
   Some(b)=>println!("HasMap.blue={}",b),
   None => println!("this not vlaue"),
 }
 let teams = vec![String::from("blue"),String::from("yellow")];
 let intial = vec![100,190];
 let scr:HashMap<_,_> = teams.iter().zip(intial.iter()).collect();
 println!("{:?}",scr);
 for (k,v) in &scr{
   println!("{}:{}",k,v);
 }

 let mut scores = HashMap::new();
    scores.insert(String::from("Blue"),10);
    scores.entry(String::from("Yellow")).or_insert(50);
    scores.entry(String::from("Blue")).or_insert(50);
    println!("{:?}",scores);

    let text = "hello world wonderful world";
    let mut map = HashMap::new();
    for word in text.split_whitespace(){
      let count = map.entry(word).or_insert(0);
      *count += 1;
    }
    println!("{:#?}",map)    
}
